# Agent Config
{% for item in consul_agent_config | dictsort %}
{{ item.0 }} = "{{ item.1 }}"

{% endfor %}

retry_join = [
{%- for server in groups['consul_servers'] -%}
  "{{ hostvars[server]['consul_addr'] }}"{{ (loop.last) | ternary('', ',') }}
{%- endfor -%}
]

{% if 'consul_servers' in group_names %}
# Server Config
server = true

ui_config {
  enabled = true
}

bootstrap_expect = 3
{% endif %}

acl = {
  enabled = {{ consul_acl.enabled | lower }}
  default_policy = "{{ consul_acl.default_policy }}"
  enable_token_persistence = {{ consul_acl.enable_token_persistence | lower }}
  tokens {
    default = "{{ consul_acl_token | default('anonymous') }}"
  }
}

node_name = "{{ ansible_hostname }}"

connect {
  enabled = {{ consul_connect_enable | lower }}
}